PassportSC._drawLoginForm = function() 
{
    this.cElement.innerHTML = '<form method="post" onSubmit="return PassportSC.doLogin();" name="loginform">' 
    + '<fieldset class="loginNav">' 
    + '    <legend class="hidden">用户登录</legend>' 
    + '    <p class="line clearfix_2"><label class="emailLabel">用户名</label>	<span class="input-blur"><em><input name="email" type="text" class="input-sohu emailInput" autocomplete="off" disableautocomplete /></em></span></p>' 
    + '    <p class="line clearfix_2"><label class="pwdLabel">密码</label><span class="input-blur"><em><input name="password" type="password" class="input-sohu passwordInput" autocomplete="off" disableautocomplete /></em></span></p>' 
    + '    <p class="line clearfix_2">' 
    + '            <label class="rememberPwd "><input name="persistentcookie" type="checkbox" value="1" />自动登录</label>' 
    + '            <a href="http://passport.17173.com/find/pwd" target="_blank" class="forgotPwd">忘记密码</a>' 
    + '   </p>' 
    + '   <p class="line clearfix_2">' 
    + '       <span class="submitNav"><input type="submit" width="70" height="21" class="loginBtn" value="登录玩家中心" alt="登录玩家中心" cache /></span>' 
    + '   </p>' 
    + '</fieldset>' 
    + '</form>';
};

PassportSC.drawPassportWait = function(str) 
{
    this.cElement.innerHTML = '' + 
    '<div class="passportc_title"><span>搜狐<b>通行证</b> <tt>|</tt> <b>17173</b></span></div>' + 
    '<div class="passportc_content" id="ppcontid">' + 
    '<div class="ppWaitMsg">' + str + '</div></div>';
};

PassportSC._drawPassportCard = function() 
{
    $('.___closeBox').click();
    var html = '<div class="passportc_title"><span>搜狐<b>通行证</b> <tt>|</tt> <b>17173</b></span><a href="javascript:PassportSC.doLogout();">退出</a></div><div class="passportc_content" id="ppcontid"><div class="listContA"></div></div>';
    this.cElement.innerHTML = html;
};

PassportSC.drawPassportInfo = function() 
{
    html = '<div class="spp_app_info"><ul><li>' + this.cookie['userid'] + '</li><li><p>欢迎您，您已经成功登录搜狐通行证！ </p></li>现在即可畅游搜狐所有服务。</li></ul></div>';
    this.iElement.innerHTML = html;
};
PassportSC.app17173 = [["http://bbs.17173.com", "社区"], 
    ["http://club.17173.com", "公会"], 
    ["http://blog.17173.com", "博客"], 
    ["http://vlog.17173.com", "播客"], 
    ["http://pic.17173.com", "截图"]];
PassportSC.app17173UserInfoUrl = "";

var Request = new Object();
Request.send = function(url, method, callback, data, urlencoded) {
    var req;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.status < 400) {
                (method == "POST") ? callback(req) : callback(req, data);
            } else {
            //alert("服务器繁忙请稍后再试!");
            }
        }
    }
    if (method == "POST") {
        req.open("POST", url, true);
        if (urlencoded)
            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        req.send(data);
    } else {
        req.open("GET", url, true);
        req.send(null);
    }
    return req;
}
Request.sendRawPOST = function(url, data, callback) {
    Request.send(url, "POST", callback, data, false);
}
Request.sendPOST = function(url, data, callback) {
    Request.send(url, "POST", callback, data, true);
}
Request.sendGET = function(url, callback, args) {
    return Request.send(url, "GET", callback, args);
}
function drawAppInfo(ele) {
    var html = '<div id="spp_app_block"><ul class="spp_app_behavior">';
    for (var i = 0; i < PassportSC.app17173.length; i++) 
    {
        html += '<li';
        if (PassportSC.app17173[i][0].match(document.domain))
            html += ' class="spp_current_app"';
        html += '><a href="' + PassportSC.app17173[i][0] + '" target="_blank">' + PassportSC.app17173[i][1] + '</a></li>';
    }
    html += '</ul>';
    if (PassportSC.app17173LogoutUrl == "" || PassportSC.app17173UserInfoUrl == "") 
    {
        html += '<div id="spp_app_info" class="spp_app_info"><ul><li>' + PassportSC.cookie['userid'] + '</li><li>' + PassportSC.loginInfo + '</li>';
        html += '<li class="passportc_logout"><a href="javascript:PassportSC.doLogout();">退出</a></li>';
        html += '</ul></div>';
    } else {
        html += '<div id="spp_app_info" class="spp_app_info"> <span class="hightlight">用户信息加载中.....</span><img src="http://bbs.17173.com/images/userinfo_loading.gif" width=16 height=16 align="bottom" /></div>';
        Request.sendGET(PassportSC.app17173UserInfoUrl, infoUpdater);
    }
    html += '</div>';
    ele.innerHTML = html;
}

function infoUpdater(request) {
    var userInfo = eval('(' + request.responseText + ')');
    var showInfo = document.getElementById("spp_app_info");
    var html = '';
    var isIE = window.ActiveXObject ? true : false;
    if (isIE) {
        var uid = PassportSC.cookie['userid'];
        flash = '<div style="float:left;width:103px;overflow: hidden;white-space: nowrap;-o-text-overflow: ellipsis;text-overflow: ellipsis;">' + userInfo.nickname + '</div><div style="float:right;margin-right:15px;"><span class="sohuMsgFlash"><embed src="http://images.chinaren.com/product/webim/mood/mood_blog.swf?UserID=' + uid + '" wmode="transparent" quality="high" pluginspage="htt p://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="-1" allowscriptaccess="always" /></span></div>'
    } 
    else {
        flash = userInfo.nickname;
    }
    switch (userInfo.status) {
        case "SYSTEM_ERROR":
        case "LOGIN_FAILED":
            showInfo.innerHTML = "登录失败";
            break;
        case "LOGIN_SUCCESS":
            // 浮云登录成功才执行回调方法
            if (typeof (window.dialogPassportLogin) != "undefined" && window.dialogPassportLogin) {
                window.dialogPassportLogin = false;
                appDidLogin(userInfo);
            }
            break;
        case "NOT_ACTIVATED":
            var uid = PassportSC.cookie['userid'];
            $("#userppid").html(uid);
            remoteaddr = userInfo.remoteaddr;
            quickActive(userInfo);
            break;
        //case 3:
        //showInfo.innerHTML = "您的帐号已被锁定!";
        //alert("对不起，您的帐号已被锁定！");
        //PassportSC.doLogout();
        //break;
        case "NOT_CERTIFICATE_EMAIL":
            showInfo.innerHTML = "您的邮箱未验证通过，请<a href='" + userInfo.gotoUrl + "'  target='_blank'>点击验证</a>";
            alert("您的帐号需要邮箱验证！");
            break;
    }
}


function refreshimg() {
    var code_source = document.getElementById("yzimg").src;
    document.getElementById("yzimg").src = code_source + "?" + Math.round(Math.random() * 100000);
}

var chinaPattern = /^[^u4E00-u9FA5]+$/;
var mailPattern = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
function chkform() {
    var pars = 'username=' + PassportSC.cookie['userid'];
    pars = pars + '&remoteaddr=' + remoteaddr;
    var nickname = $('#t_nickname');
    if (!nickname.val()) {
        alert("呢称不能为空！");
        nickname.focus();
        return false;
    }
    if (!chinaPattern.test(nickname.val())) {
        alert("呢称请输入中文字符！");
        nickname.focus();
        return false;
    }
    pars = pars + '&nickname=' + nickname.val();
    var sex_1 = $("#t_sex_1");
    var sex_2 = $("#t_sex_2");
    if (!sex_1.attr("checked") && !sex_2.attr("checked")) {
        alert('请选择性别!');
        sex_1.focus();
        return false;
    }
    if (sex_1.attr("checked"))
        pars = pars + '&sex=1';
    else
        pars = pars + '&sex=0';
    var email = $("#t_email");
    if (!email.val()) {
        alert('请输入邮件地址！');
        email.focus();
        return false;
    }
    if (!mailPattern.test(email.val())) {
        alert('请填写有效的Email地址！');
        email.focus();
        return false;
    }
    pars = pars + '&email=' + email.val();
    var validcode = $("#t_validcode");
    if (!validcode.val()) {
        alert('请输入验证码！');
        validcode.focus();
        return false;
    }
    pars = pars + '&validcode=' + validcode.val();
    var agree = $("#i_Agree");
    if (!agree.attr("checked")) {
        alert('您还未同意“17173网站服务条款”');
        agree.focus();
        return false;
    }
    pars = pars + '&agree=' + agree.val();
    $.ajax({
        url: "auth?act=ACTIVE",
        data: pars,
        type: "POST",
        cache: false,
        success: function(result) {
            var jsonData = eval('(' + result + ')');
            switch (jsonData.status) {
                case "LOGIN_SUCCESS":
                    PassportSC.isLogin = true;
                    // 激活成功
                    appDidLogin();
                    break;
                default:
                    switch (jsonData.errorCode) {
                        case "6":
                            alert('用户名已存在');
                            break;
                        case "7":
                            alert('呢称已存在');
                            break;
                        case "9":
                            alert('IP不允许');
                            break;
                        default:
                            alert('激活失败' + jsonData.errorCode);
                    }
            }
        }
    });
}

// 显示登录对话框
function showLoginDialog(cbLoginSuccess, cbLoginCancel, loginContext) {
    // 移除页面现有的浮动层
    safeRemoveBox();
    
    if (typeof (cbLoginSuccess) == "function") {
        window.cbLoginSuccess = cbLoginSuccess;
    }
    if (typeof (cbLoginCancel) == "function") {
        window.cbLoginCancel = cbLoginCancel;
    }
    window._loginContext = loginContext;

    // 判断是否已登录
    PassportSC.parsePassportCookie();
    if (typeof (PassportSC.cookie['userid']) != "undefined") {
        appDidLogin();
        return;
    }
    
    window.dialogPassportLogin = true;

    // 登录时，传入回调函数
    
    $.XYTipsWindow({
        ___title: "登录",
        ___content: "id:loginWin",
        //___content:"iframe:win-login_bak.shtml",
        ___showbg: true,
        ___drag: "___boxTitle",
        ___width: "464px",
        ___height: "228px",
        ___boxWrapBdColor: "#666",
        ___boxBdColor: "#a5a5a5",
        ___fnClose: function() {
            if (typeof (PassportSC.cookie['userid']) == "undefined") {
                if (typeof (cbLoginCancel) == "function") {
                    cbLoginCancel();
                }
            }
        }
    //关闭窗口后执行的函数
    })

    //input 样式设定
    $(".input-sohu").focus(function() {
        $(this).parent().parent().addClass("input-focus");
    });
    $(".input-sohu").blur(function() {
        $(this).parent().parent().removeClass("input-focus");
    });

    // 登录按钮
    $(".login-win-btn").click(function() {
        // 移除页面现有的浮动层
        safeRemoveBox();
        
        $.XYTipsWindow({
            ___title: "登录",
            ___content: "id:loginWin",
            //___content:"iframe:win-login_bak.shtml",
            ___showbg: true,
            ___drag: "___boxTitle",
            ___width: "464px",
            ___height: "228px",
            ___boxWrapBdColor: "#666",
            ___boxBdColor: "#a5a5a5"
        })
    });

    // 注册按钮
    $(".reg-win-btn").click(function() {
        // 移除页面现有的浮动层
        safeRemoveBox();
        
        $.XYTipsWindow({
            ___title: "注册",
            ___content: "id:regWin",
            //___content:"iframe:win-reg.shtml",
            //___offsets:{left:"30px",top:"50px"},
            ___showbg: true,
            ___drag: "___boxTitle",
            ___width: "614px",
            ___height: "540px",
            ___boxWrapBdColor: "#666",
            ___boxBdColor: "#a5a5a5",
            ___fns: function() {
                // ie系列, iframe放在display:none的元素里, 得要这么hack一下, 要不然显示不出来:
                var elem = $('#regWin .bd')[0];
                var html = elem.innerHTML;
                setTimeout(function() {
                    elem.innerHTML = html;
                }, 1);
            }
        })
    });

}


// 显示快速激活
function quickActive(userInfo) {
    // 移除页面现有的浮动层
    safeRemoveBox();
    
    $.XYTipsWindow({
        ___title: "",
        ___content: "id:quickjh",
        //___content:"iframe:./active.shtml",
        ___showbg: true,
        ___drag: "___boxTitle",
        ___width: "510px",
        ___height: "410px",
        ___boxWrapBdColor: "#666",
        ___boxBdColor: "#a5a5a5",
        ___fnClose: function() {
            if (typeof (cbLoginCancel) == "function") {
                cbLoginCancel(userInfo);
            }
        }
    })
}


function safeRemoveBox() {
    try {
        $.XYTipsWindow.removeBox();
    } catch (e) {
    }
    ;
}

/**
$(function(){
	quickActive();
})
**/


